import BaseTan from '../../../_resource/common/modules/JiessDialog/BaseTan.js'
class Tan extends BaseTan {
	static tanInstance(...args) {
		return Tan.initInstance(new Tan(...args));
	}
	open({ title, children, onOk, onCancel, width = 960, ...param }) {
		const { exec, instance, onClick } = this;
		instance().open(function(show) {
			const close = () => show.value = false;
			return {
				width,
				title,
				destroyOnClose: true,
				onOk: onClick(this, onOk, close),
				children: exec(children, [close, show]),
				onCancel: onClick(this, onCancel, close),
				...param
			};
		});
	}
	// 仅一个按钮的弹框，且按钮仅用于关闭弹框
	alert({ title, children, onClose, button = {}, ...param }) {
		// 使用确定按钮，隐藏取消按钮
		const { exec, instance, onClick } = this;
		instance().open(function(show) {
			const close = () => show.value = false;
			const {
				type = 'primary', text = '关闭',
					...okButtonProps
			} = exec(button, [close, show]);
			return {
				title,
				// 右上角的叉叉
				closable: true,
				// 强制渲染 Modal
				forceRender: true,
				// 关闭时销毁 Modal 里的子元素
				destroyOnClose: true,
				// 点击确定，关闭弹框
				onOk: onClick(this, onClose, close),
				onCancel: close,
				okText: text,
				okType: type,
				okButtonProps,
				cancelText: '取消',
				// 隐藏取消按钮
				cancelButtonProps: { style: { display: 'none' } },
				children: exec(children, [close, show]),
				...param
			};
		});
	}
};
// ----------------------------------------
export default Tan.tanInstance;